<?php

namespace frontend\modules\yii2\models;

use Yii;
use yii\base\Model;

/**
 * Login form
 */
class User extends Model
{

    public $firstName;
    public $lastName;
    public $birthday;

    public function rules()
    {
        return [
            [["firstName", "lastName", "birthday"], "required"]
        ];
    }

    public function fields()
    {
        return [
            "name" => function(){
                return $this->firstName . " · " . $this->lastName;
            },
            "birthday" => function(){
                return date("Y-m-d", $this->birthday);
            }
        ];
    }

    public function extraFields()
    {
        return [
            "country" => function(){
                if ($this->lastName == "斯坦森") {
                    return "美国";
                } else {
                    return "中国";
                }
            }
        ];
    }

}